
const state = {
  camera1: {
    url: '',
    fenceFlag: false,
    detectFlag: false,
    monitor_flag: 0,
    monitorFlag: false
  },
  camera2: {
    url: '',
    fenceFlag: false,
    detectFlag: false,
    monitor_flag: 0,
    monitorFlag: false
  },
  camera3: {
    url: '',
    fenceFlag: false,
    detectFlag: false,
    monitor_flag: 0,
    monitorFlag: false
  },
  camera4: {
    url: '',
    fenceFlag: false,
    detectFlag: false,
    monitor_flag: 0,
    monitorFlag: false
  },
  useVideo: false,
  monitor_flag: 0,
  loop: 0
}
const mutations = {
  setCameraData(state, data) {
    console.log(data.url)
    state.camera1.url = data.url
    state.camera1.fenceFlag = data.fenceFlag
    state.camera1.detectFlag = data.detectFlag
    state.camera1.monitor_flag = data.monitor_flag
    state.camera1.monitorFlag = data.monitorFlag
    if (!data.monitorFlag) {
      state.camera1.monitor_flag = 0
    } else {
      state.camera1.monitor_flag = 1
    }
  },
  setCamera2Data(state, data) {
    console.log('mutations setCamera2Data')
    console.log(data.url)
    state.camera2.url = data.url
    state.camera2.fenceFlag = data.fenceFlag
    state.camera2.detectFlag = data.detectFlag
    state.camera2.monitor_flag = data.monitor_flag
    state.camera2.monitorFlag = data.monitorFlag
    if (!data.monitorFlag) {
      state.camera2.monitor_flag = 0
    } else {
      state.camera2.monitor_flag = 1
    }
  },
  setCamera3Data(state, data) {
    state.camera3.url = data.url
    state.camera3.fenceFlag = data.fenceFlag
    state.camera3.detectFlag = data.detectFlag
    state.camera3.monitor_flag = data.monitor_flag
    state.camera3.monitorFlag = data.monitorFlag
    if (!data.monitorFlag) {
      state.camera3.monitor_flag = 0
    } else {
      state.camera3.monitor_flag = 1
    }
  },
  setCamera4Data(state, data) {
    state.camera4.url = data.url
    state.camera4.fenceFlag = data.fenceFlag
    state.camera4.detectFlag = data.detectFlag
    state.camera4.monitor_flag = data.monitor_flag
    state.camera4.monitorFlag = data.monitorFlag
    if (!data.monitorFlag) {
      state.camera4.monitor_flag = 0
    } else {
      state.camera4.monitor_flag = 1
    }
  },
  SET_VIDEO: (state, useVideo) => {
    state.useVideo = useVideo
  },
  SET_LOOP: (state, loop) => {
    state.loop = loop
  }
}
const actions = {
  setCamera1({ commit }, data) {
    commit('setCameraData', data)
  },
  setCamera2({ commit }, data) {
    console.log('dataURl:' + data.url + data.monitorFlag)
    console.log('调用actions')
    commit('setCamera2Data', data)
  },
  setCamera3({ commit }, data) {
    commit('setCamera3Data', data)
  },
  setCamera4({ commit }, data) {
    commit('setCamera4Data', data)
  },
  setVideo({ commit }, useVideo) {
    commit('SET_VIDEO', useVideo)
  },
  setLoop({ commit }, loop) {
    commit('SET_LOOP', loop)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
